<?
	session_start();
	require_once ('core/conn.php');

	$db = get_conn();
	check_session();



function get_menu_q(){
	$where_roles .=" rm.id_rol in ( ".$_SESSION['session_roles'].") " ;	
	
	$sql ="select distinct m.id_category, cm.name from modulos m, menu_categories cm where
			m.id_category = cm.id_category order by cm.level asc";
	$result = mysql_query($sql);
	$categoria = "";
	$columnas = 1;
	$counter=0;	
	if($result){
		while($row = mysql_fetch_array($result)){
			$items = get_menu_category_items($row['id_category'],$where_roles);
			if($items!=''){

					$data.="<tr><td  valign='top' >
								<TABLE width='100%' border='0' cellPadding='0' cellSpacing='0' valign='top'>
									<TR >
									  <TD class='menu_categoria_title' >".$row['name']."</TD>
									</TR>
									<TR>
									  <TD align='left' nowrap >
									  <div >
											<ul>
											".$items."
											</ul>
									  </div>
									  </TD>
									</TR>

								</TABLE>
							</td>
							</tr>";
			}//!=''					

		}//while
		return "<table width='100%'  border='0'>".$data."</table>";
	}else{
		
		error_handling(__FUNCTION__.$sql,mysql_error());
	}	
}

function get_menu_category_items($category,$where_roles){
	$sql ="select distinct m.name,m.link,m.id_category,m.target,m.description from modulos m,rol_modulo rm  where
			".$where_roles." and m.mostrar ='Y' and rm.id_modulo =m.id_modulo and id_category='".$category."' order by m.nivel asc";
	$result = mysql_query($sql);
	if($result){
		$cantidad_hijos = mysql_num_rows($result);
		if($cantidad_hijos >0){
			while($row = mysql_fetch_array($result)){
					$data.="<li class='menu5' style='padding:2px;'>
								<a title='".$row['description']."' target='".$row['target']."' href='".$row['link']."' >".$row['name']."</a>
							</li>";
				
			}//while
			//return "<table border='0'>".$data."</table>";
			return $data;
		}
		return "";
	}else{
		error_handling(__FUNCTION__.$sql,mysql_error());
	}	

}

if($_SESSION['session_is_admin'] ==1){
	$src ="welcome.php";
}else{
	$src ="welcome_user.php";	
}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Genosha Gate Keeper</title>
<style>
.menu_categoria_title{
 color:#FF6638;
 text-transform:uppercase;
 font-size:13px;
 font-weight:bold;
 font-family:Arial, Helvetica, sans-serif;
}

.menu5{
 font-size:10px;
 font-weight:bold;
 font-family:Arial, Helvetica, sans-serif;
}

</style>
<style type="text/css">
<!--
body {
	background-image: url(images/bg_ticostore.jpg);
}
.style5 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #7F7D19;
	font-weight: bold;
}
a:link {
	color: #7F7D19;
	text-decoration: none;
}
a:visited {
	color: #7F7D19;
	text-decoration: none;
}
a:hover {
	color: #7F7D19;
	text-decoration: underline;
}
a:active {
	color: #7F7D19;
	text-decoration: none;
}
.style3 {	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #FF6600;
	font-weight: bold;
}
.style15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #7F7D19; font-weight: bold; }
-->
</style>
<script>

function do_print(ptarget){
				
		ptarget.focus();
		ptarget.print(); 		
	}
</script>
</head>

<body>
<table width="988" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td width="232" valign="top"><div align="left" style="height:650px; width:200px; overflow:auto"><? echo get_menu_q();?></div></td>
    <td width="735" valign="top"><iframe frameborder="0" name="main_frame" id="main_frame" src="<?php echo $src; ?>" scrolling="Auto" height="800" width="975" ></iframe></td>
  </tr>
</table>
</body>
</html>
